/*
 * 文件名:EmployeeServiceImpl.java
 * 创建时间:2010-10-01
 * 版本:2.0
 * 版权所有:杨涛 walle1027@gmail.com
 */
package com.yangtao.wms.ast.employee.service.impl;
import com.yangtao.wms.ast.employee.service.*;
import org.apache.commons.lang.StringUtils;
import java.io.Serializable;
import java.util.*;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yangtao.framework.hibernate.Selector;
import com.yangtao.framework.common.*;
import com.yangtao.framework.service.*;
import com.yangtao.framework.util.*;
import com.yangtao.ast.dao.EmployeeDao;
import com.yangtao.ast.domain.Employee;
import com.yangtao.wms.ast.employee.web.*;
/**
 * 
 * @author 代码生成器 v-2.0
 * @version 2.0
 */
@Service()
public class EmployeeServiceImpl extends BaseService implements EmployeeService {

	@Autowired
	protected EmployeeDao employeeDao;
	/**
	* 查询记录，并且分页
	*
	* @param  model 页面参数
	*/
	@Override
	public EmployeeModel list(EmployeeModel model) {
			employeeDao.findPageByCondition(model.getPage(), model.getCondition());
	return model;
	}

	/**
	* 取得唯一记录
	*
	* @param  model 页面参数
	*/
	@Override
	public EmployeeModel loadEmployee(EmployeeModel model) {
		if (StringHelper.isNotEmpty(model.getEmployee().getId())) {
		model.setEmployee(employeeDao.loadForReview(model.getEmployee().getId()));
		}
		return model;
	}

	/**
	* 新增记录
	*
	* @param model 页面参数
	*/
	@Override
	public EmployeeModel addEmployee(EmployeeModel model){
		//VO
		Employee employeeVO = model.getEmployee();
		//PO
		Employee employeePO = new Employee();
		mapper.map(employeeVO, employeePO);
		//保存对象
		employeeDao.save(employeePO);
		//增加保存成功的消息
		model.addInfo("add.success");
		return model;
	}

	/**
	* 更新记录
	*
	* @param model 页面参数
	*/
	@Override
	public EmployeeModel updateEmployee(EmployeeModel model){
		//VO
		Employee employeeVO = model.getEmployee();
		//主键
		String employeeId = employeeVO.getId();
		//PO
		Employee employeePO = employeeDao.load(employeeId);
		//复制页面属性
		mapper.map(employeeVO, employeePO);
		//TODO 增加其他属性
		//TODO 更新关联对象
		//构造关联从对象
		//增加保存成功的消息
		model.addInfo("update.success");
		return model;
	}

	/**
	* 删除记录
	*
	* @param  model 页面参数
	*/
	@Override
	public EmployeeModel deleteEmployee(EmployeeModel model){
		employeeDao.delete(model.getEmployee().getId());
		model.addInfo("delete.success");
		return model;
	}
}
